const express = require('express');
      router = express.Router();
      cookieParser = require('cookie-parser')

app.use(cookieParser())

router.get('/sign',(req,res) => {
  res.render('user/login',{
    title:'登录',
    back:true
  })
})



//登陆
router.get('/login/:username/:password',(req,res) => {
    var name = req.params.username
    var pass = req.params.password
    
    User.find({username:name},function(err,data){
      
      if(data[0]){
        
        if(pass == data[0].password){
            var userId = data[0].id
            res.clearCookie('userId')
            res.cookie('img',data[0].image)
            res.cookie('username',name)
            res.cookie('userId',userId)
            send(res,'success','登陆成功..')
        }else{
          send(res,'fail','您输入的密码错误，请重新输入···')
        }
      }
      else{
        send(res,'fail','您还没有注册，请您注册···')
      }
    })
   
})

module.exports = router